package com.weng.cloud.service8881.hystrix;

import com.cloud.api.hystrix.HystrixService;
import com.cloud.api.hystrix.NbaPlayer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: weng
 * @Date: 2022/3/11
 * @Description: com.weng.cloud.service8881.hystrix
 *
 * 之前遇到过一个非常奇怪的现象：
 *  我有一个接口模块weng-cloud-feign
 *  这个模块没有启动类，但是有server.application.name=weng-cloud-feign
 *  于是乎，启动后feign调用者、提供者的实例名全变成了weng-cloud-feign
 *  最后导致 ribbon 的 loadBalance 嗝屁了
 */
@RestController
public class DependencyController {

//    @Autowired
//    private HystrixServiceImpl hystrixServiceImpl;

    @Resource
    private HystrixService hystrixServiceImpl;

    @PostMapping("/testDependency/{arg}")
    public NbaPlayer testDependency(@PathVariable String arg){
        System.err.println("一人攻沙虐全场");
        /*Map<Integer,String> map = new HashMap<>();
        map.put(8,"d-will");
        map.put(7,"kd");
        map.put(3,"beal");
        map.put(0,arg);*/
        return this.hystrixServiceImpl.testDependency(arg);
    }

    @GetMapping("/testHystrixFeign")
    public String testHystrixFeign(){
        System.err.println("冰霜秒全场");
        return this.hystrixServiceImpl.testHystrixFeign();
    }
}
